package im.device.config.widget;

import android.app.Application;
import app.log.AppLog;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKGeneralListener;

public class BMapApiApplication extends Application {
	
	private static final String TAG = BMapApiApplication.class.getSimpleName();
	
	public static BMapApiApplication mBMapApiApplication;
	//百度MapAPI的管理类
	public BMapManager mBMapMan = null;
	// 授权Key
	public String mStrKey = "37D6580D0610A54EBE7C277F94C6B6AD239D30DA";
	
	// 常用事件监听，用来处理通常的网络错误，授权验证错误等
	protected static class MyGeneralListener implements MKGeneralListener {
		@Override
		public void onGetNetworkState(int iError) {
			AppLog.e(TAG, "BMapApiApplication 网络出错！");
		}

		@Override
		public void onGetPermissionState(int iError) {
			if (iError ==  MKEvent.ERROR_PERMISSION_DENIED) {
				AppLog.e(TAG, "BMapApiApplication 授权Key出错！");
			}
		}
	}

	@Override
    public void onCreate() {
		AppLog.v(TAG, "BMapApiApplication onCreate");
		mBMapApiApplication = this;
		mBMapMan = new BMapManager(this);
		mBMapMan.init(this.mStrKey, new MyGeneralListener());
		mBMapMan.getLocationManager().setNotifyInternal(10, 5);
		super.onCreate();
	}

	@Override
	public void onTerminate() {
		//建议在您app的退出之前调用mapadpi的destroy()函数，避免重复初始化带来的时间消耗
		if (mBMapMan != null) {
			mBMapMan.destroy();
			mBMapMan = null;
		}
		super.onTerminate();
	}


}
